/*
 *   Copyright 1999-2016 Asiainfo Technologies(China),Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */
package com.kingboy.kbg.devop.email;



import org.simplejavamail.email.Email;
import org.simplejavamail.email.EmailBuilder;
import org.simplejavamail.mailer.Mailer;
import org.simplejavamail.mailer.config.ServerConfig;

import java.util.Properties;

/**
 * Created by digimonster on 16/10/17.
 */
public class MailUtils {
    public void sendEmail(ACLUser user) {
        String url = "http://kingboy/home";
        Email email = new EmailBuilder()
                .from("devops-admin","kingboy0502@qq.com")
                .to(user.getUsername(),user.getEmail())
                .subject("注册邮箱验证")
                .textHTML(user.getName()
                        + "，您好：<br/>感谢您注册devops服务!</br>"
                        + "<b>验证您注册的邮箱地址</b><br/>请点击下面的链接来确认您的注册<br/>"
                        + "<a href='" + url + "'>确认!请点击这里验证此邮件</a><br/>"
                        + "如果您不能点击上述标签为“确认!”的链接，您还可以通过复制（或输入）下面的URL到地址栏中来验证您的邮件地址。"
                        + "<a href='" + url + "'>" + url + "</a><br/>"
                        + "如果您认为这是垃圾邮件，请忽略此邮件。")
                .build();
        Properties props = new Properties();
        props.setProperty("mail.smtp.timeout", 30 * 1000+"");
        props.setProperty("mail.smtp.connectiontimeout", 10 * 1000+"");
        Mailer mailer = new Mailer(new ServerConfig("smtp.qq.com",25,"kingboy0502@qq.com","youyou2010"));
        mailer.applyProperties(props);
        mailer.sendMail(email);
    }

    public static void main(String[] args) {
        ACLUser user = new ACLUser();
        user.setUsername("guojinbao");
        user.setEmail("guojinbao@chinasoftinc.com");
        user.setName("guojinbao");
        MailUtils mailUtils = new MailUtils();
        mailUtils.sendEmail(user);
    }
}
